package com.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.javabean.Member;
import com.javabean.Orders;
import com.javabean.Product;
import com.javabean.Traveller;
import com.mapper.MemberMapper;
import com.mapper.OrdersMapper;
import com.mapper.ProductMapper;
import com.mapper.TravellerMapper;
import com.service.OrdersManagerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
@Service
public class OrdersManagerServiceImpl implements OrdersManagerService {
    @Resource
    OrdersMapper ordersMapper;
    @Resource
    ProductMapper productMapper;
    @Resource
    MemberMapper memberMapper;
    @Resource
    TravellerMapper travellerMapper;

    @Override
    public ArrayList<Orders> findAll(int page,int limit,String key,String value) {
        PageHelper.startPage(page,limit);
        return ordersMapper.selectAll( key, value);
    }

    @Override
    public Orders showOrders(int id) {
        Orders orders = ordersMapper.selectById(id);
        //查询关联的产品
        Product product = productMapper.selectById(orders.getProductId());
        orders.setProduct(product);
        //查询关联的会员
        Member members = memberMapper.selectById(orders.getMemberId());
        orders.setMember(members);
        //查询关联的旅客
        ArrayList<Traveller> travellers = travellerMapper.selectByOId(orders.getId());
        orders.setTravellers(travellers);

        return orders;
    }
}
